|
1
|
|
|
var assert = require('chai').assert, |
|
2
|
|
|
GedcomX = require('../'); |
|
3
|
|
|
|
|
4
|
|
|
describe('Relationship', function(){ |
|
5
|
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
|
7
|
|
|
var newRelationship = new GedcomX.Relationship(), |
|
8
|
|
|
relationship = GedcomX.Relationship(); |
|
9
|
|
|
assert.instanceOf(newRelationship, GedcomX.Relationship, 'An instance of Relationship is not returned when calling the constructor with new.'); |
|
10
|
|
|
assert.instanceOf(relationship, GedcomX.Relationship, 'An instance of Relationship is not returned when calling the constructor without new.'); |
|
11
|
|
|
}); |
|
12
|
|
|
|
|
13
|
|
|
it('Create with JSON', function(){ |
|
14
|
|
|
var relationship = GedcomX.Relationship({ |
|
15
|
|
|
type: 'http://gedcomx.org/Couple', |
|
16
|
|
|
person1: { |
|
17
|
|
|
resource: 'http://identifier/for/person/1' |
|
18
|
|
|
}, |
|
19
|
|
|
person2: { |
|
20
|
|
|
resource: 'http://identifier/for/person/2' |
|
21
|
|
|
}, |
|
22
|
|
|
facts: [ |
|
23
|
|
|
{ |
|
24
|
|
|
type: 'http://gedcomx.org/Marriage' |
|
25
|
|
|
} |
|
26
|
|
|
] |
|
27
|
|
|
}); |
|
28
|
|
|
assert.equal(relationship.getType(), 'http://gedcomx.org/Couple'); |
|
29
|
|
|
assert.equal(relationship.getPerson1().getResource(), 'http://identifier/for/person/1'); |
|
30
|
|
|
assert.equal(relationship.getPerson2().getResource(), 'http://identifier/for/person/2'); |
|
31
|
|
|
assert.equal(relationship.getFacts().length, 1); |
|
32
|
|
|
assert.equal(relationship.getFacts()[0].getType(), 'http://gedcomx.org/Marriage'); |
|
33
|
|
|
}); |
|
34
|
|
|
|
|
35
|
|
|
it('Create with mixed data', function(){ |
|
36
|
|
|
var relationship = GedcomX.Relationship({ |
|
37
|
|
|
type: 'http://gedcomx.org/Couple', |
|
38
|
|
|
person1: { |
|
39
|
|
|
resource: 'http://identifier/for/person/1' |
|
40
|
|
|
}, |
|
41
|
|
|
person2: { |
|
42
|
|
|
resource: 'http://identifier/for/person/2' |
|
43
|
|
|
}, |
|
44
|
|
|
facts: [ |
|
45
|
|
|
GedcomX.Fact({ |
|
46
|
|
|
type: 'http://gedcomx.org/Marriage' |
|
47
|
|
|
}) |
|
48
|
|
|
] |
|
49
|
|
|
}); |
|
50
|
|
|
assert.equal(relationship.getType(), 'http://gedcomx.org/Couple'); |
|
51
|
|
|
assert.equal(relationship.getPerson1().getResource(), 'http://identifier/for/person/1'); |
|
52
|
|
|
assert.equal(relationship.getPerson2().getResource(), 'http://identifier/for/person/2'); |
|
53
|
|
|
assert.equal(relationship.getFacts().length, 1); |
|
54
|
|
|
assert.equal(relationship.getFacts()[0].getType(), 'http://gedcomx.org/Marriage'); |
|
55
|
|
|
}); |
|
56
|
|
|
|
|
57
|
|
|
it('Build', function(){ |
|
58
|
|
|
var relationship = GedcomX.Relationship() |
|
59
|
|
|
.setType('http://gedcomx.org/Couple') |
|
60
|
|
|
.setPerson1(GedcomX.ResourceReference().setResource('http://identifier/for/person/1')) |
|
61
|
|
|
.setPerson2(GedcomX.ResourceReference().setResource('http://identifier/for/person/2')) |
|
62
|
|
|
.addFact(GedcomX.Fact().setType('http://gedcomx.org/Marriage')); |
|
63
|
|
|
assert.equal(relationship.getType(), 'http://gedcomx.org/Couple'); |
|
64
|
|
|
assert.equal(relationship.getPerson1().getResource(), 'http://identifier/for/person/1'); |
|
65
|
|
|
assert.equal(relationship.getPerson2().getResource(), 'http://identifier/for/person/2'); |
|
66
|
|
|
assert.equal(relationship.getFacts().length, 1); |
|
67
|
|
|
assert.equal(relationship.getFacts()[0].getType(), 'http://gedcomx.org/Marriage'); |
|
68
|
|
|
}); |
|
69
|
|
|
|
|
70
|
|
|
it('toJSON', function(){ |
|
71
|
|
|
var data = { |
|
72
|
|
|
type: 'http://gedcomx.org/Couple', |
|
73
|
|
|
person1: { |
|
74
|
|
|
resource: 'http://identifier/for/person/1' |
|
75
|
|
|
}, |
|
76
|
|
|
person2: { |
|
77
|
|
|
resource: 'http://identifier/for/person/2' |
|
78
|
|
|
}, |
|
79
|
|
|
facts: [ |
|
80
|
|
|
{ |
|
81
|
|
|
type: 'http://gedcomx.org/Marriage' |
|
82
|
|
|
} |
|
83
|
|
|
] |
|
84
|
|
|
}, relationship = GedcomX.Relationship(data); |
|
85
|
|
|
assert.deepEqual(relationship.toJSON(), data); |
|
86
|
|
|
}); |
|
87
|
|
|
|
|
88
|
|
|
it('constructor does not copy instances', function(){ |
|
89
|
|
|
var obj1 = GedcomX.Relationship(); |
|
90
|
|
|
var obj2 = GedcomX.Relationship(obj1); |
|
91
|
|
|
assert.strictEqual(obj1, obj2); |
|
92
|
|
|
}); |
|
93
|
|
|
|
|
94
|
|
|
}); |